package com.itheima.spring.bestpractive.utils;

import com.itheima.spring.bestpractive.common.util.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @version 1.0
 * @author: HZY
 * @date: 2025/6/29 16:52
 * @Content: 获取token中的员工id
 */
@Component
public class TokenForId {
    @Autowired
    private  StringRedisTemplate stringRedisTemplate;
    @Autowired
    private  JwtUtil jwtUtil;
    public  String getId(String token){
        String s = stringRedisTemplate.opsForValue().get(token);
        Claims claims = jwtUtil.parseToken(s);
        return claims.getSubject();
    }
}
